#include "uart.c"

/**
 * 屏幕循环输出一个数字。
 * 实现两个按键，按键1按下，将屏幕输出的数字-1
 * 按键2按下，将屏幕输出的数字+1
 *
 * 实现按键持续按下的效果，如果持续按下，屏幕每次输出3次数字后，数字变化
 */

void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}
int count1 =0;
int count2=0;
int shuzi=0;
void main()
{
    uart_init();
    while(1)
    {
    if(P2_0==0)
    {
      while(P2_0==0)
      {
      count1 = count1+1;
        if(count1 ==3)
        {
         shuzi=shuzi +1;
         count1 =0;
        }
        printf("%d\n",shuzi);
 
        delay_ms(500); 
      }
      shuzi = shuzi +1;
      
    }
    if(P2_1==0)
    {
      while(P2_1==0)
      {
      count2 = count2+1;
        if(count2 ==3)
        {
         shuzi=shuzi -1;
         count2 =0;
        }
        printf("%d\n",shuzi);

        delay_ms(500); 
      }
      shuzi = shuzi -1;
    }
    printf("%d\n",shuzi);
    delay_ms(500);    
    }
}